<?php

namespace app\admin\controller\cc;

use app\common\controller\Backend;

/**
 * workflow管理
 *
 * @icon fa fa-circle-o
 */
class Workflow extends Backend
{

    /**
     * Workflow模型对象
     * @var \app\admin\model\cc\Workflow
     */
    protected $noNeedRight = ['detail'];

    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\cc\Workflow;

    }

    /**
     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
     */


    public function detail()
    {
        $ids = 0;
        $url = $_SERVER['REQUEST_URI'];
        if (false !== strpos($url, '/ids/')) {
            $urls = explode('?', $url);
            $url = $urls[0];
            $urls = explode('/', $url);
            $size = count($urls);
            $ids = $urls[$size - 1];
        }

        $row = $this->model->get(['id' => $ids]);
        if (!$row)
            $this->error(__('No Results were found'));


        $this->view->assign("ids", $ids);
        $this->view->assign("row", $row);

        $nodeDataArray = array();
        $nodeDataArray[] = array("key" => "P1", "category" => "Process", "pos" => "150 120", "text" => "Process");
        $nodeDataArray[] = array("key" => "P2", "category" => "Process", "pos" => "330 320", "text" => "Tank");
        $nodeDataArray[] = array("key" => "V1", "category" => "Valve", "pos" => "270 120", "text" => "V1");
        $nodeDataArray[] = array("key" => "P3", "category" => "Process", "pos" => "150 420", "text" => "Pump");
        $nodeDataArray[] = array("key" => "V2", "category" => "Valve", "pos" => "150 280", "text" => "VM", "angle" => 270);
        $nodeDataArray[] = array("key" => "V3", "category" => "Valve", "pos" => "270 420", "text" => "Reserve Tank", "angle" => 180);
        $nodeDataArray[] = array("key" => "P4", "category" => "Process", "pos" => "450 140", "text" => "VA");
        $nodeDataArray[] = array("key" => "V4", "category" => "Valve", "pos" => "390 60", "text" => "VB");
        $nodeDataArray[] = array("key" => "V5", "category" => "Valve", "pos" => "450 260", "text" => "V2", "angle" => 90);

//        {"from":"P1", "to":"V1"},
//        {"from":"P3", "to":"V2"},
//        {"from":"V2", "to":"P1"},
//        {"from":"P2", "to":"V3"},
//        {"from":"V3", "to":"P3"},
//        {"from":"V1", "to":"V4"},
//        {"from":"V4", "to":"P4"},
//        {"from":"V1", "to":"P2"},
//        {"from":"P4", "to":"V5"},
//        {"from":"V5", "to":"P2"}
        $linkDataArray = array();
        $linkDataArray[] = array("from" => "P1", "to" => "V1");
        $linkDataArray[] = array("from" => "P3", "to" => "V2");
        $linkDataArray[] = array("from" => "V2", "to" => "P1");
        $linkDataArray[] = array("from" => "P2", "to" => "V3");
        $linkDataArray[] = array("from" => "V3", "to" => "P3");
        $linkDataArray[] = array("from" => "V1", "to" => "V4");
        $linkDataArray[] = array("from" => "V4", "to" => "P4");
        $linkDataArray[] = array("from" => "V1", "to" => "P2");
        $linkDataArray[] = array("from" => "P4", "to" => "V5");
        $linkDataArray[] = array("from" => "V5", "to" => "P2");

        $gModel = array(
            "class" => "go.GraphLinksModel",
            "nodeDataArray" => $nodeDataArray,
            "linkDataArray" => $linkDataArray
        );

        $this->view->assign("gModel", json_encode($gModel));

        return $this->view->fetch();
    }


}
